import json

from django.db import models


class Templates(models.Model):
    title = models.CharField(max_length=24, verbose_name='单据名字')
    content = models.TextField(verbose_name='单据模板')

    class Meta:
        db_table = 'tb_templates'

    def __str__(self):
        return self.title


"""
[{"label":"姓名","type":"text", "value":""},
{"label":"假别","type":"select", "value":"", "values":["事假","病假"]}]
"""


# 工单实例
class TempInstance(models.Model):
    c_time = models.DateTimeField(auto_now_add=True)
    u_time = models.DateTimeField(auto_now=True)
    user = models.ForeignKey('users.User', on_delete=models.PROTECT)
    content = models.TextField(verbose_name='单据内容')

    class Meta:
        db_table = 'tb_tempinstance'


# 流转表
class Flow(models.Model):
    STATUS = (
        (0, '未处理'),
        (1, '同意'),
        (2, '不同意'),
    )
    user = models.ForeignKey('users.User', on_delete=models.PROTECT)
    instance = models.ForeignKey('workflow.TempInstance', related_name='flow', on_delete=models.PROTECT)
    status = models.IntegerField(choices=STATUS, default=0)
    comment = models.CharField(max_length=256, null=True, blank=True, default=None)
    seq = models.IntegerField(verbose_name='顺序编号')

    class Meta:
        db_table = 'tb_flow'

    def __str__(self):
        return "%s_%s_%s"%(self.user.username,self.instance_id,self.status)